﻿@{
    ViewBag.Title = "Administracion de Usuarios";
}

<style>
    #p {
        color: green;
    }

    #table_div {
        color: red;
    }
</style>

<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

<div style="padding-top:220px">
<h2>Administracion de Usuarios</h2>

@Html.ActionLink("Crear Usuario", "CreateView", "Admin") - @Html.ActionLink("Volver", "Index", "Account")

<p id="p">@ViewBag.mensaje</p>

<div id='table_div'></div>

<table border="1">
    <thead>
        <tr>
            <td>Usuario</td>
            <td>Empresa</td>
            <td>Rol</td>
            <td>Operaciones</td>
        </tr>
    </thead>
    <tbody>
        @foreach (var i in Model)
        {
            <tr>
                <td>@i.user</td>
                <td>@i.codEmp</td>
                <td>@i.rol</td>
                <td>
                    @if (ViewBag.nombre != i.user)
                    {
                        <a href="@Url.Action("Borrar", "Admin", new {user = i.user})">Borrar</a>
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
    </div>

<script type='text/javascript'>
    google.load('visualization', '1', { packages: ['table'] });
      //google.setOnLoadCallback(drawTable);

      /*var form = $("#form");
      form.submit(funcion1);

      function funcion1() {*/
          var url = "@Url.Action("Datos", "Admin")";
          var promesa = $.get(url);
          promesa.done(drawTable);
          /*return false;
      }*/

    function drawTable(datos) {
        var data = new google.visualization.DataTable();
        var options = { 'showRowNumber':true, 'width':'300px' };
          var i;
          console.log(datos);
        data.addColumn('string', 'Usuario');
        data.addColumn('number', 'Codigo de Empresa');
        data.addColumn('string', 'Rol');
        $.each(datos, function()
        {            
                data.addRows([
                    [this.user, this.codEmp, this.rol]
                ]);
                var table = new google.visualization.Table(document.getElementById('table_div'));
            
            table.draw(data, options);
        }
        );
    }
    </script>